package io.openmessaging.demo;

import java.util.Set;

import com.markhsiu.main.MarkMap;

import io.openmessaging.KeyValue;

public class DefaultKeyValue implements KeyValue {
	
    private final MarkMap kvs;
    
    public DefaultKeyValue() {
    	kvs = new MarkMap();
	}
    
    public DefaultKeyValue(boolean extension) {
    	kvs = new MarkMap(extension);
  	}
    
    @Override
    public KeyValue put(String key, int value) {
        kvs.put(key, String.valueOf(value));
        return this;
    }

    @Override
    public KeyValue put(String key, long value) {
        kvs.put(key, String.valueOf(value));
        return this;
    }

    @Override
    public KeyValue put(String key, double value) {
        kvs.put(key, String.valueOf(value));
        return this;
    }

    @Override
    public KeyValue put(String key, String value) {
        kvs.put(key, value);
        return this;
    }

    @Override
    public int getInt(String key) {
        return Integer.parseInt(getString(key));
    }

    @Override
    public long getLong(String key) {
        return Long.parseLong(getString(key));
    }

    @Override
    public double getDouble(String key) {
        return Double.parseDouble(getString(key));
    }

    @Override
    public String getString(String key) {
        return kvs.get(key);
    }

    @Override
    public Set<String> keySet() {
        return kvs.keySet();
    }
 
    @Override
    public boolean containsKey(String key) {
        return kvs.containsKey(key);
    }
    
 
    
    public  byte[] mapToBytes() {
    	return	null;
	}
    
    public  int  size() {
    	return	kvs.size();
	}
  
    
    public  void clear() {
    		kvs.clear();
	}
    
    public  void reset() {
		kvs.reset();
}
    
    public  int  mapToBytes(byte[] data, int offset) {
    	return	kvs.toData(data, offset);
	}

    public void put(String key, byte[] data, int offset, int length){
    	kvs.put(key, data, offset, length);
    }
    
    public  DefaultKeyValue bytesToMap(byte[] data,  int offset, int length) {
    	kvs.toMap(data, offset, length);
    	return this;
	}
    
    public  DefaultKeyValue bytesToMap(byte[] data) {
    	kvs.toMap(data);
    	return this;
	}
	

	@Override
	public String toString() {
		return kvs.toString();
	}
}
